package com.pd;

import com.pd.pojo.PdOrder;
import com.pd.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "orderQueue")//负责从rabbitmq接收消息
public class OrderConsumer {
    @Autowired
    private OrderService orderService;
    @RabbitHandler //加了这个注解代表这个方法处理消息 ，这个注解只能有一个(指定处理消息的方法 一个类中只能有一个)
    public void receiveOrder(PdOrder pdOrder) throws Exception {
        orderService.saveOrder(pdOrder);
        System.out.println("订单已存储");
    }

}
